/******************************************************************************************
 * Import
 ******************************************************************************************/

// module
import Taro, { Component } from '@tarojs/taro'

// project
import { CPage, CContent, CHeader, CFooter, CFloat, CAround, CBetween, CCenter, CRow, CColumn, CWrap, CLine, CHand, CItemX, CItemY, CText, CLabel, CSvg, CImage, CButton } from '../../library/comp';
import { Base64, Gen, Time, Zip, Session, Storage, Http } from '../../library/func';
import Icon from '../../project/style/icon';
import CommentList from '../../project/comp/commentList/Proj_Prod_Comment_List';
import DoHttp from '../../project/func/http/http';

/******************************************************************************************
 * Export Class
 ******************************************************************************************/

export default class Comment extends Component {

	/*------------------------------------------------------------------------------------
	 * 初始化
	 *-----------------------------------------------------------------------------------*/
	constructor(props) {
		super(props);

		/**
		 * state
		 */
		this.state = {
			id:6,
			allNumber:666,
			photoNumber:333,
			activeAll:true,
			allPage:1,
			photoPage:1,
			data: [],
		}
	}

	/*------------------------------------------------------------------------------------
	 * 生命周期
	 *-----------------------------------------------------------------------------------*/
	// WillMount
	componentWillMount() {
		this.setState({
			// id:this.$router.params.id,
			// allNumber:this.$router.params.comment_total_count,
			// photoNumber:this.$router.params.comment_image_count,
		})
	}
	// didMount
	componentDidMount() {
		this.getHttp(1,0)
	}
	
	/*------------------------------------------------------------------------------------
	 * 事件处理
	 *-----------------------------------------------------------------------------------*/
	// 接口获取
	getHttp = ( page, image ) => {
		DoHttp.get({
			url:'product/comment.php',
			data:{
				pid:this.state.id,
				page:page,
				image:image
			},
			success:(data) => {
				this.setState({
					data:data
				})
				console.log('data ===================>',data)
			}
		})
	}
    // 全部与有图切换
    allChange = ( page, img, e )=> {
		this.getHttp( page, img );
		// 增长页数
		// let pageN;
		// if(img){
		// 	pageN = 'photoPage';
		// }else{
		// 	pageN = 'allPage';
		// }
		this.setState({
			activeAll:!this.state.activeAll,
			// [pageN]:page+1,
		});
		console.log('page||page',page)
		console.log('img||img',img)
		
    }

	/*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/

	/*------------------------------------------------------------------------------------
	 * 渲染
	 *-----------------------------------------------------------------------------------*/
	render () {
		return (
			<CPage>
				<CContent bg='#f3f3f3'>
					
					{/* 全部与有图 */}
					{
						this.state.activeAll ? (
							<CRow h='100' px='40' bg='#fff' >
								<CButton style='font-size:28rpx;' pa='10 20' class='commentActive'>全部 ({this.state.allNumber})</CButton>
								<CButton style='font-size:28rpx;' pa='10 20' class='commentNormal'
									onClick={this.allChange.bind(this,this.state.photoPage,1)}
								>有图 ({this.state.photoNumber})</CButton>
							</CRow>
						) : (
							<CRow h='100' px='40' bg='#fff' >
								<CButton style='font-size:28rpx;' pa='10 20' class='commentNormal'
									onClick={this.allChange.bind(this,this.state.allPage,0)}
								>全部 ({this.state.allNumber})</CButton>
								<CButton style='font-size:28rpx;' pa='10 20' class='commentActive'>有图 ({this.state.photoNumber})</CButton>
							</CRow>
						)
					}

					{/* 评价列表 */}
					{
						this.state.data.map( item => {
							return (
								<CommentList bg='#fff' mt='20' pa='20' data={{
									id:item.id,
									avatar:item.user_object.set_head,
									nick:item.user_object.set_nick,
									content:item.object.set_content,
									images:item.object.set_image,
									time:item.created,
								}} >
								</CommentList>
							)
						}) 
					}
					
					

				</CContent>
			</CPage>
		)
	}
}


